<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- 组件的使用 -->
        <menu-item @enlarge-text='handle($event)'></menu-item>
        <div>{{fontSize}}</div>
    </div>
    <script src="../js/vue.min.js"></script>
    <script>
        // 组件定义
        Vue.component('menu-item', {
            data: function() {
                return {
                    count: 0
                }
            },
            // 可携带参数,也可不携带参数
            template: `<button @click='$emit("enlarge-text",0.1)'>扩大字体</button>
            <button @click='$emit("enlarge-text")'>扩大字体</button>`,
            methods: {
                handle: function() {
                    this.count++
                }
            }
        });

        let vm = new Vue({
            el: "#app",
            data: {
                fontSize: 10,
            },
            methods: {
                handle: function(val) {
                    this.fontSize += val;
                }
            }
        })
    </script>
</body>

</html>